using System.Linq.Expressions;
using CMS.Repository;

namespace CMS.Service.Impl;

public class BaseService<T>(IBaseRepository<T> repository) where T : class, new() {
    public Task<bool> AddAsync(T entity) {
        return repository.AddAsync(entity);
    }

    public Task<bool> DeleteAsync(T entity) {
        return repository.DeleteAsync(entity);
    }

    public IQueryable<T> Get(Expression<Func<T, bool>> whereLambda) {
        return repository.Get(whereLambda);
    }

    public IQueryable<T> GetPage<TS>(int pageIndex, int pageSize, out int totalCount,
                                     Expression<Func<T, bool>> whereLambda, Expression<Func<T, TS>> orderByLambda,
                                     bool isAsc) {
        return repository.GetPage<TS>(pageIndex, pageSize, out totalCount, whereLambda, orderByLambda, isAsc);
    }

    public Task<bool> UpdateAsync(T entity) {
        return repository.UpdateAsync(entity);
    }
}